.org 0x0
.global _start

_start:
	jal x1,in
	
.org 0x40
	li x1,0x00000000
	lb x3,0x0(x1)
	li x1,0x10000003
	sb x3,0x0(x1)
	
	li x1,0x20000004
	lw x2,0x0(x1)
	li x3,0xffffffff
	xor x2,x2,x3
	sw x2,0x0(x1)
	
	
	li x1,0x10000003
	csrrs x2,mepc,x0
	sb x2,0x0(x1)
	
	srl x2,x2,2
	sb x2,0x0(x1)
	
	srl x2,x2,2
	sb x2,0x0(x1)
	
	srl x2,x2,2
	sb x2,0x0(x1)
	
	li x1,0x10000003
	csrrs x2,mtval,x0
	sb x2,0x0(x1)
	
	srl x2,x2,2
	sb x2,0x0(x1)
	
	srl x2,x2,2
	sb x2,0x0(x1)
	
	srl x2,x2,2
	sb x2,0x0(x1)
	
	li x1,0x50000000
	li x2,0x00000003
	sw x2,0x0(x1)
	
	mret
	
.org 0x100
in:
	li x1,0x10000000
	li x2,0x040000d9
	sw x2,0x0(x1)
	
	li x1,0x10000003
	li x2,'o'
	sb x2,0x0(x1)
	
	li x1,0x00000000
	li x2,'p'
	sb x2,0x0(x1)
	
	#亮灯
	li x1,0x20000008
	li x2,0xffffffff
	sw x2,0x0(x1)
	
	li x1,0x2000000c
	li x2,0x00000000
	sw x2,0x0(x1)
	
	li x1,0x20000004
	li x2,0x47404106
	sw x2,0x0(x1)
	
	#设置中断
	li x3,0x40000040
	csrrw x4,mtvec,x3
	li x1,0x80
	csrrw x2,mie,x1
	li x1,0x08
	csrrw x2,mstatus,x1
	
	#设置定时器
	li x1,0x50000008
	li x2,0x00500000
	sw x2,0x0(x1)
	
	li x1,0x50000000
	li x2,0x00000003
	sw x2,0x0(x1)
_loop1:
	
	
	addi x5,x5,1
	j _loop1
